import com.google.appengine.api.blobstore.BlobKey
import com.google.appengine.api.images.*

//System.out.println(params)

def blob = new BlobKey(params.key)
byte[] data;
String memkey = params.key 
	



if (memkey in memcache) {
	System.out.println("image found in cache "+memkey)
	data = memcache[memkey]
} else {
	System.out.println("image not found in cache -> blobstore")
	
	blob.withStream { InputStream stream ->
		data = stream.getBytes();
	}
	memcache[memkey] = data
}

//Image ima = ImagesServiceFactory.makeImage(data)
//double percent = 0.3
//ima = ima.resize((int)ima.getHeight()*percent, (int)ima.getWidth()*percent)

sout << data
	
//blobstore.serve blob, response 
	

	


